import createEle from "./creatEle";
import updateChildren from "./updateChildren";
export default function patchVNode (oldVnode, newVnode) {
    if (oldVnode === newVnode) {
        return
    }
    if (newVnode.text != undefined && (newVnode.children == undefined || newVnode.children.length == 0)) {
        // 新节点有text属性（没有chlidren）
        if (newVnode.text != oldVnode) {
            oldVnode.elm.innerText = newVnode.text
        }
    } else {
        // 新节点没有text属性(有children)
        if (oldVnode.children != undefined && oldVnode.children.length > 0) {
            updateChildren(oldVnode.elm, oldVnode.children, newVnode.children)
        } else {
            oldVnode.elm.innerText = ''
            for (let i = 0; i < newVnode.children.length; i++) {
                const element = newVnode.children[i];
                oldVnode.elm.appendChild(element)                    
            }
        }
    }
}